package com.my.controller;

import com.my.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@CrossOrigin("*")
@RequestMapping("/user")
public class UserController {

    UserService userService;

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    @RequestMapping("/loginByPassword")
    public String loginByPassword(String username, String password) {
        return this.userService.loginByPassword(username, password);
    }

    @RequestMapping("/loginByFace")
    public String loginByFace(String MD5) {
        return this.userService.loginByFace(MD5);
    }

    @RequestMapping("/loginByPhone")
    public String loginByPhone(String phone, String code) {
        return this.userService.loginByPhone(phone, code);
    }

    @RequestMapping("/loginByEmail")
    public String loginByEmail(String email, String code) {
        return this.userService.loginByEmail(email, code);
    }


    @RequestMapping("/sendPhoneMessage")
    public String sendPhoneMessage(String phone) {
        return this.userService.sendPhoneMessage(phone);
    }

    @RequestMapping("/sendEmailMessage")
    public String sendEmailMessage(String email) {
        return this.userService.sendEmailMessage(email);
    }


    @RequestMapping("/register")
    public String register(String username, String password, String face, String phone, String email) {
        return this.userService.register(username, password, face, phone, email);
    }


    @RequestMapping("/author")
    public String getAuthor(HttpServletRequest req) {
        return this.userService.getAuthor(req);
    }

    @RequestMapping("/changePassword")
    public String changePassword(String password, HttpServletRequest req) {
        return this.userService.changePassword(password, req);
    }

}
